﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BarberShop.BLL;
using BarberShop.Data;

public partial class DeviceAdd : BasePage
{
    public int Id
    {
        get
        {
            return string.IsNullOrEmpty(Request.QueryString["id"]) ? 0 : Convert.ToInt32(Request.QueryString["id"]);
        }
    }
    public int StoreId
    {
        get
        {
            return string.IsNullOrEmpty(Request.QueryString["storeid"]) ? 0 : Convert.ToInt32(Request.QueryString["storeid"]);
        }
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BandStoresinfo();
            BandDeviceInfo();
            if (StoreId != 0)
            {
                drp_sotresId.SelectedValue = StoreId.ToString();
                drp_sotresId.Enabled = false;
            }
        }
    }
    #region 绑定门店
    public void BandStoresinfo()
    {
        this.drp_sotresId.DataSource = StoresInfoBLL.GetStoresList(new BarberShop.Model.StoresInfoSearch());
        this.drp_sotresId.DataTextField = "StoreName";
        this.drp_sotresId.DataValueField = "ID";
        this.drp_sotresId.DataBind();
    }
    #endregion

    #region 绑定设备信息
    public void BandDeviceInfo()
    {
        if (Id != 0)
        {
            var info = DeviceInfoBLL.GetDeviceInfo(Id);
            drp_sotresId.SelectedValue = info.Stores_ID.ToString();
            txt_mac.Text = info.MacAddress;
        }
    }
    #endregion

    protected void btn_add_Click(object sender, EventArgs e)
    {
        DeviceInfo info = new DeviceInfo();
        if (Id != 0)
        {
            info = DeviceInfoBLL.GetDeviceInfo(Id);
        }
        else
        {
            info.LineStatus = 0;
        }
        info.MacAddress = txt_mac.Text.Trim();
        info.Stores_ID = int.Parse(drp_sotresId.SelectedValue);
        bool r = DeviceInfoBLL.SaveDeviceInfo(info);
        if (r)
        {
            MsgBox("设备保存成功！");
        }
        else { MsgBox("保存失败！"); }

    }
}
